#include <vector>
#include <iostream>
using namespace std;

#include "Player.h"



Player::Player()
{
m_points=0;
}

Player::Player(int jerseyNo)
{
m_points=0;
m_jersey=jerseyNo;
}

Player::Player(int jerseyNo, string Name)
{
m_jersey=jerseyNo;
m_name=Name;

}

string Player::getPlayerName()
{
return m_name;
}

int Player::getPlayerPoints()
{

return m_points;
}

int Player::getPlayerNumber()
{
return m_jersey;
}

void Player::setPlayerNumber(int number)
{
m_jersey=number;
}


void Player::incPlayerPoints(int points )

{
m_points+=points;

}

int Player::getPointsByPer(int per)
{
int pointsThisPer=0;
	for (int i=0;i<playerShots.size();i++)
	{
		if (((playerShots[i].getPer())==per)&&(playerShots[i].getMade()))
		{
		pointsThisPer+=playerShots[i].getPoints();
		}
	}
return pointsThisPer;
//return m_points;
}


int Player::getShotAttempts(int filterPoints)
{
int attempts=0;
	for (int i=0;i<playerShots.size();i++)
	{
		if ((playerShots[i].getPoints())==filterPoints)
		{
		attempts+=1;
		}
	}
return attempts;
}

int Player::getShotSuccess(int filterPoints)
{
int success=0;
	for (int i=0;i<playerShots.size();i++)
	{
		if (((playerShots[i].getPoints())==filterPoints)&&(playerShots[i].getMade()))
		{
		success+=1;
		}
	}
return success;
}

double Player::getShotPercent(int filterPoints)
{
int success=0, attempts=0;

	attempts=getShotAttempts(filterPoints);
	success=getShotSuccess(filterPoints);
	if (attempts!=0)
	{
	return static_cast<double>(success)/attempts;
	}
	else
	{
	return 0;
	}
}








void Player::addPlayerEvent(Event * somePlayerEvent)
{
playerEvents.push_back(somePlayerEvent);

}

int Player::countPlayerEvents(string eventType)
{
int countEvents=0;
	vector<Event*>::iterator it;

	for (it=playerEvents.begin(); it < playerEvents.end(); it++)	
	{

		if (((*it)->getType())==eventType)
		{
		countEvents++;
		}
	}
return countEvents;

}



void Player::addShot(Shot * ptrToShot)
{
playerShots.push_back(*ptrToShot);
m_points+=((*ptrToShot).getPoints());
}

//Define this function for use with vector find function
bool Player::operator== (Player P2)
{
bool areEqual=false;
	if (m_jersey==P2.getPlayerNumber())
	{
	areEqual=true;	
	}
return areEqual;

}


/*
double Player::getFGPercent()
{
loop through shot vector
if 1 point show, add to total
if made, add to made total
computer percent
display percent
}
*/
